﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.IO;

namespace ScriptEditor
{
    /// <summary>
    /// OutputUI.xaml 的交互逻辑
    /// </summary>
    public partial class OutputUI : Window
    {
        public bool IsOk = false;
        public string modAuthor = "";
        public string modName = "";
        public string modSign = "";
        public string modDescription = "";
        public string[] modFile = new string[0];
        public string modEntry = "";

        public OutputUI()
        {
            InitializeComponent();
        }

        private void AddScenario_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();
            dialog.Filter = "剧本文件|*.json";
            dialog.Multiselect = true;
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                foreach(string path in dialog.FileNames)
                {
                    if (!ScenarioList.Items.Contains(Path.GetFullPath(path)))
                    {
                        ScenarioList.Items.Add(Path.GetFullPath(path));
                    }
                }
            }
        }

        private void Output_Click(object sender, RoutedEventArgs e)
        {
            if (ModName.Text == "")
            {
                MessageBox.Show("Mod的名称不能为空");
                return;
            }
            if (ModEntry.Text == "")
            {
                MessageBox.Show("Mod的入口不能为空");
                return;
            }
            if (ModName.Text == ModSign.Text&&ModSign.Text.Length<10)
            {
                MessageBox.Show("Mod的签名是MOD的唯一标识，为了避免冲突，不能和名称相同，且长度大于10，具有唯一性");
                return;
            }
            modName = ModName.Text;
            modAuthor = ModAuthor.Text;
            modSign = ModSign.Text;
            modDescription = ModDescription.Text;
            modEntry = ModEntry.Text;
            modFile = new string[ScenarioList.Items.Count];
            ScenarioList.Items.CopyTo(modFile, 0);
            IsOk = true;
            Close();
        }

        private void ScenarioList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ScenarioList.SelectedIndex != -1)
            {
                ModEntry.Text = (string)ScenarioList.SelectedItem;
            }
            else
            {
                ModEntry.Text = "";
            }
        }
    }
}
